home *** CD-ROM | disk | FTP | other *** search
- Rem -------------------------
- Rem Invader!
- Rem -------------------------
- CLS
- Rem Set up Arrays
- Let aliensPerRow = 3
- Let numRows = 4
- Let numAliens = aliensPerRow * numRows
- Dim alienSprite(numAliens)
- Dim alienAlive(numAliens)
- Dim alienBomb(numAliens)
- Dim bombX(numAliens)
- Dim bombY(numAliens)
- Dim bombDropping(numAliens)
- Rem Set the sprites
- For a = 1 To numAliens
- Let alienSprite(a) = LoadSprite("ufo")
- CycleSprite alienSprite(a) speed 10
- Let alienBomb(a) = LoadSprite("invbomb")
- CycleSprite alienBomb(a) Speed 5
- Let alienAlive(a) = TRUE
- Let bombDropping(a) = FALSE
- Next a
- Let gun = LoadSprite("invgun")
- Let misl = LoadSprite("invmisl")
- CycleSprite misl speed 30
- Let boom = LoadSprite("woozy01")
- SetSprite boom range 0 to 11
- Rem Set up game variables
- Let width = 75
- Let height = 35
- Let gunMoveSpeed = 10
- Let top = 0
- Let left = 0
- Let yDropEachTime = 2
- Let gunX = 140
- Let gunY = 230
- Let mislSpeed = 15
- Let mislFired = FALSE
- Let bombSpeed = 1
- Let PlayerHit = FALSE
- Let alienSpeed = 1
- Let GameOver = FALSE
- Let Lives = 3
- Let Score = 0
- Let ExitTimer = 0
- Let RunGame = TRUE
-
- Rem ----
- Rem Display instructions
- Rem Then run game
- Rem ----
- Gosub Instructions
- Gosub DoAlienGame
- Rem Hide all remaining aliens
- For a = 1 to numAliens
- HideSprite alienSprite(a)
- HideSprite alienBomb(a)
- Next a
- Rem Hide any remaining gun or missle
- HideSprite misl
- HideSprite gun
- Rem Tell user he can play again
- Home
- TextColor 235
- Print
- Print "Click RUN to play again!"
- End
-
- Rem Subroutines
-
- Rem ----
- Rem Give Instructions
- Rem ----
- Instructions:
- CLS
- TextColor 190 'Eye Blue
- Print "Invaders!"
- Print
- Print "Use the Left and Right arrow keys"
- Print "to move your gun, and the Space Bar"
- Print "to shoot."
- Print
- Print "The aliens get faster and madder"
- Print "the better you do, so be careful!"
- Print
- Print "Press a key when ready to play"
- while inkey$ <> ""
- wend
- while inkey$ = ""
- wend
- Rem Now set up game screen
- Rem using a background
- CLS
- Background "Earth"
- Return
-
- Rem ----
- Rem Handle alien movements
- Rem and call player subroutine
- Rem ----
- DoAlienGame:
- move = 1
- while RunGame
- Rem 'move' negative to move left
- If move > 0 then
- move = alienSpeed
- else
- move = -alienSpeed
- Endif
- Rem 'going' is true until we bump an edge
- going = TRUE
- While going
- Rem 'aliensLeft' is used to count how many remain
- aliensLeft = 0
- Rem Subroutine 'Play' handles gun and missles
- Gosub Play
- Rem Draw all of the aliens
- SuspendUpdate
- For a = 1 to numAliens
- Rem calculate the position of this alien
- r = Int((a-1) / numRows)
- c = (a-1) mod numRows
- y = top + r * height
- x = left + c * width
- Rem See if alien should drop a bomb
- If bombDropping(a) = FALSE Then
- If alienAlive(a) AND Random(1,100) < 5 Then
- bombX(a) = x + 27
- bombY(a) = y + 33
- bombDropping(a) = TRUE
- Endif
- Endif
- Rem update a dropping bomb
- If bombDropping(a) Then
- SetSprite alienBomb(a) to bombX(a),bombY(a)
- bombY(a) = bombY(a) + bombSpeed
- If bombY(a) > 240 Then
- HideSprite alienBomb(a)
- bombDropping(a) = FALSE
- Endif
- Rem See if bomb hit player
- If SpriteHitSprite(alienBomb(a), gun) then
- Rem Player Hit
- HideSprite alienBomb(a)
- bombDropping(a) = FALSE
- If PlayerHit = FALSE Then
- playerHit = TRUE
- Sound "EXP_BIG"
- EndIf
- Endif
- Endif
-
- Rem Move the alien
- If alienAlive(a) Then
- aliensLeft = aliensLeft + 1
- Rem See if we bump the edge and need to reverse direction
- If move > 0 And x > 250 Then
- If spriteHitPoint(alienSprite(a),319,y+20) Then going = FALSE
- EndIf
- If move < 0 and x < 0 Then Going = FALSE
-
- Rem see if we collide with gun
- If y > 210 Then
- Rem Kill Player
- PlayerHit = TRUE
- Rem Reset aliens
- for t = 1 to numAliens
- alienAlive(t) = FALSE
- bombDropping(t) = FALSE
- Next t
- EndIf
-
- Rem Put alien at right spot on screen
- SetSprite alienSprite(a) to x,y
-
- Rem See if missle hits this alien
- If mislFired Then
- If SpriteHitSprite(alienSprite(a), misl) then
- Rem Alien hit
- HideSprite alienSprite(a)
- HideSprite misl
- Sound "EXP_FAR"
- mislFired = FALSE
- alienAlive(a) = FALSE
- Rem Score
- score = score + 50 * yDropEachTime
- Rem every alien killed makes game go a little faster
- alienSpeed = alienSpeed + .3
- Endif
- Endif
- Endif
- Next a
- ResumeUpdate
- Rem move the row of aliens
- left = left + move
- Rem If all aliens gone, end loop
- If aliensLeft = 0 then going = FALSE
- Wend ' (going)
- Rem now move the opposite direction
- move = -move
- going = TRUE
- If aliensLeft Then
- Rem drop down a line, and drop bombs a little faster
- top = top + yDropEachTime
- bombSpeed = bombSpeed + .2
- Else
- Rem Reset the aliens for next round
- For a = 1 to numAliens
- alienAlive(a) = TRUE
- Next a
- Rem put them back at the top
- top = 0
- Rem Make them drop a little faster in next round
- yDropEachTime = yDropEachTime + 1
- Rem make a sound to announce new round
- If PlayerHit = FALSE Then Sound "BOING1"
- Endif
- Wend
- Return
-
- Rem ----
- Rem Handle Player
- Rem ----
- Play:
- Rem handle gun with arrow keys
- if KeyDown("CurLeft") Then
- gunX = gunX - gunMoveSpeed
- if gunX < 0 then gunX = 0
- EndIf
- if KeyDown("CurRight") Then
- gunX = gunX + gunMoveSpeed
- if gunX > 300 then gunX = 300
- Endif
- Rem see if we are firing missle
- if mislFired = FALSE Then
- if KeyDown("space") Then
- mislY = 210
- mislX = gunX + 15
- mislFired = TRUE
- Endif
- Endif
-
- Rem handle player getting hit
- if PlayerHit = TRUE Then
- Rem just got hit
- If GetSpriteFrame(boom) = 0 Then
- HideSprite gun
- SetSprite boom to gunx,guny - 20
- Rem run through the explosion only once
- CycleSprite boom speed 10 Once
- Rem player loses one of his lives
- Lives = Lives - 1
- If Lives = 0 Then
- GameOver = TRUE
- Rem game is over, but let's not end until a timer expires
- ExitTimer = timer()
- Rem put Game Over text on the screen
- DrawText "@14,bold,RED,TIMES@GAME OVER" at 120,120
- Endif
- Else
- Rem see if done exploding
- If GetSpriteFrame(boom) = 10 Then
- HideSprite boom
- StopSprite boom
- If GameOver = FALSE Then
- Rem reset player (if game not over)
- PlayerHit = FALSE
- SetSprite boom frame 0
- Else
- Rem End game when timer expires
- If Timer() - ExitTimer > 3500 Then RunGame = FALSE
- Endif
- Endif
- Endif
- Else
- Rem position the gun
- SetSprite gun to gunx,guny
- Endif
-
- Rem update a fired missle
- If mislFired AND GameOver = FALSE then
- SetSprite misl to mislX,mislY
- mislY = mislY - mislSpeed
- if mislY < -20 then mislFired = FALSE
- Endif
-
- Rem Display the score and lives
- DrawText "@16,BOLD,COURIER,BLACK@Score: @PURPLE@"+str$(score) at 2,220
- DrawText "@16,BOLD,COURIER,BLACK@Lives: @PURPLE@"+str$(Lives) at 230,220
-
- return
-
-
-
-
-
-
-
-
-
-
-
-
-
-